/**
 * This toolbar provides a menu to control the visual presentation of a map.
 * The user can move and zoom the map and change the displayed map type.
 * 
 * @author Kim Pommert
 * @version %I%, %G%
 */
qx.Class.define("qooxdoosample.cocktail.ui.MapControlToolbar",{
	
	extend: qx.ui.toolbar.ToolBar,
	
	/**
	 * Class constructor.
	 * Instantiates an object of that class.
	 */
	construct: function()
	{
		this.base(arguments);
	},
	
	
	members: 
	{

		/**
		 * Initializes the buttons and menus of the toolbar.
		 * 
		 * @param aMap	{qooxdoosample.cocktail.maps.IDynamicMap} 
		 * 					The map that is controlled using the components of this toolbar
		 */		
		init: function(aMap)
		{	
			this.add(this.getMovePart(aMap));
			this.add(this.getZoomPart(aMap));		
			this.add(this.getMapTypePart(aMap));
			this.add(this.getProviderMapControlPart(aMap));
		},
		
		/**
		 * Generates and initializes the panel containing the buttons to move the map.
		 * 
		 * @param aMap	{qooxdoosample.cocktail.maps.IDynamicMap} 
		 * 					The map that is controlled using the components of this toolbar
		 * 
		 * @return {qx.ui.toolbar.Part} The panel with all its buttons
		 */
		getMovePart: function(aMap)
		{
			var movePart = new qx.ui.toolbar.Part;
			
			var moveLeftButton = new qx.ui.toolbar.Button("left", "qooxdoosample/icons/go-previous.png");
	  		moveLeftButton.addListener("execute", function(e) {
    			aMap.moveLeft();
  			});
  			
  			var moveRightButton = new qx.ui.toolbar.Button("right", "qooxdoosample/icons/go-next.png");
	  		moveRightButton.addListener("execute", function(e) {
    			aMap.moveRight();
  			});
  			
  			var moveUpButton = new qx.ui.toolbar.Button("up", "qooxdoosample/icons/go-up.png");
	  		moveUpButton.addListener("execute", function(e) {
    			aMap.moveUp();
  			});
  			
  			var moveDownButton = new qx.ui.toolbar.Button("down", "qooxdoosample/icons/go-down.png");
	  		moveDownButton.addListener("execute", function(e) {
    			aMap.moveDown();
  			});
  			
  			movePart.add(moveLeftButton);
  			movePart.add(moveRightButton);
  			movePart.add(moveUpButton);
  			movePart.add(moveDownButton);
  			
  			movePart.setShow("icon");
  			
  			return movePart;
		},
		
		/**
		 * Generates and initializes the panel containing the buttons to zoom in/out of the map.
		 * 
		 * @param aMap	{qooxdoosample.cocktail.maps.IDynamicMap} 
		 * 					The map that is controlled using the components of this toolbar
		 * 
		 * @return {qx.ui.toolbar.Part} The panel with all its buttons
		 */
		getZoomPart: function(aMap)
		{
			var zoomPart = new qx.ui.toolbar.Part;
  			var zoomOutButton = new qx.ui.toolbar.Button("-", "qooxdoosample/icons/zoom-out.png");
	  		zoomOutButton.addListener("execute", function(e) {
    			aMap.zoomOut();
  			});
  			zoomOutButton.setShow("icon");
  			
  			var zoomInButton = new qx.ui.toolbar.Button("+", "qooxdoosample/icons/zoom-in.png");
	  		zoomInButton.addListener("execute", function(e) {
    			aMap.zoomIn();
  			});
  			zoomInButton.setShow("icon");
  			
  			var zoomLevelButton = new qx.ui.toolbar.MenuButton("Zoom Level");
  			zoomLevelButton.setMenu(this.getZoomLevelMenu(aMap));
  			
  			zoomPart.add(zoomInButton);
  			zoomPart.add(zoomOutButton);
  			zoomPart.add(zoomLevelButton);
  			return zoomPart;
		},
		
		/**
		 * Generates and initializes the menu for the dropdown button to set the zoom level.
		 * 
		 * @param aMap	{qooxdoosample.cocktail.maps.IDynamicMap} 
		 * 					The map that is controlled using the components of this toolbar
		 * 
		 * @return {qx.ui.menu.Menu} The menu for zoom level dropdown
		 */
		getZoomLevelMenu: function(aMap)
		{
			var menu = new qx.ui.menu.Menu();
  			
  			var level5Button = new qx.ui.menu.Button("5");
  			level5Button.addListener("execute", function(e){
  				aMap.setZoomLevel(5);
  			});
  			
  			 
  			var level10Button = new qx.ui.menu.Button("10");
  			level10Button.addListener("execute", function(e){
  				aMap.setZoomLevel(10);
  			}); 
  			
  			
  			var level15Button = new qx.ui.menu.Button("15");
  			level15Button.addListener("execute", function(e){
  				aMap.setZoomLevel(15);
  			}); 
  			
  			var level20Button = new qx.ui.menu.Button("20");
  			level20Button.addListener("execute", function(e){
  				aMap.setZoomLevel(20);
  			}); 
  			
  			
  			menu.add(level5Button);
  			menu.add(level10Button);
  			menu.add(level15Button);
  			menu.add(level20Button);
  			return menu;
		},
		
		/**
		 * Generates and initializes the panel containing the buttons change the map type.
		 * 
		 * @param aMap	{qooxdoosample.cocktail.maps.IDynamicMap} 
		 * 					The map that is controlled using the components of this toolbar
		 * 
		 * @return {qx.ui.toolbar.Part} The panel with all its buttons
		 */
		getMapTypePart: function(aMap)
		{
			var typePart = new qx.ui.toolbar.Part;
			
			var normalMapButton = new qx.ui.toolbar.Button("Map");
	  		normalMapButton.addListener("execute", function(e) {
    			aMap.setMapType(qooxdoosample.cocktail.maps.IDynamicMap.MAP_TYPE_NORMAL);
  			});
  			
  			var satelliteMapButton = new qx.ui.toolbar.Button("Satellite");
	  		satelliteMapButton.addListener("execute", function(e) {
    			aMap.setMapType(qooxdoosample.cocktail.maps.IDynamicMap.MAP_TYPE_SATELLITE);
  			});
  			
  			var hybridMapButton = new qx.ui.toolbar.Button("Hybrid");
	  		hybridMapButton.addListener("execute", function(e) {
    			aMap.setMapType(qooxdoosample.cocktail.maps.IDynamicMap.MAP_TYPE_HYBRID);
  			});
  			
  			
  			typePart.add(normalMapButton);
  			typePart.add(satelliteMapButton);
  			typePart.add(hybridMapButton);
  			return typePart;
				
		},
		
		/**
		 * Generates and initializes the panel containing the buttons to show/hide the provider's control panel.
		 * 
		 * @param aMap	{qooxdoosample.cocktail.maps.IDynamicMap} 
		 * 					The map that is controlled using the components of this toolbar
		 * 
		 * @return {qx.ui.toolbar.Part} The panel with all its buttons
		 */
		getProviderMapControlPart: function(aMap)
		{
			var controlPart = new qx.ui.toolbar.Part;
			
			var showControlsButton = new qx.ui.toolbar.Button("show controls");
	  		showControlsButton.addListener("execute", function(e) {
    			aMap.showControls();
  			});
  			
  			var hideControlsButton = new qx.ui.toolbar.Button("hide controls");
	  		hideControlsButton.addListener("execute", function(e) {
    			aMap.hideControls();
  			});
  			  			
  			
  			controlPart.add(showControlsButton);
  			controlPart.add(hideControlsButton);
  			return controlPart;
		},
		
				
		/**
		 * When the map provider is changed, this method has to be called, to update 
		 * all click listeners of the components in this toolbar.
		 * 
		 * @param aMap	{qooxdoosample.cocktail.maps.IDynamicMap} 
		 * 					The map that is controlled using the components of this toolbar
		 */
		updateMap: function(aMap)
		{
			this.removeAll();
			this.init(aMap);
		}
	}
});